<?php 
include_once '../util/ArrayList.php';
include_once '../util/db/model/Product.php';
include_once '../util/db/model/ProdType.php';
include_once '../util/db/model/ProdAttr.php';
include_once '../util/db/model/ProdSubType.php';
include_once '../util/db/model/SupplierBrand.php';
include_once '../util/db/model/ProductSearchPara.php';
include_once '../util/db/service/ProductDBUtil.php';
include_once '../util/db/service/ProdAttrDBUtil.php';
include_once '../util/db/service/OrderListDBUtil.php';
$prodAttrDBUtil=new ProdAttrDBUtil();
$orderListDBUtil=new OrderListDBUtil();
$ol_id=null;
if(isset($_POST["ol_id"])){
	$ol_id=$_POST["ol_id"];
}else{
	$ol_id=$_GET['ol_id'];
}

$orderList=$orderListDBUtil->queryByOlid($ol_id);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/admin_page.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>無標題文件</title>
<!-- InstanceEndEditable -->
<style type="text/css">
<!--
#cantainer {
	width: 955px;
	margin-right: 33px;
	margin-left: 33px;
}
#header {
	width: 955px;
	margin-bottom: 10px;
	background-image: url(../../images/top_bg.png);
	height: 82px;
}
#body {
	width: 955px;
	margin-bottom: 10px;
}
#footer {
	width: 955px;
}
.style2 {color: #666666;
	font-size: 12px;
}
#contant_list {
	float: left;
	width: 180px;
	margin-right: 10px;
}
.style17 {color: #74B9E5; font-size: 14px; }
.style43 {font-size: 12px; color: #666666; font-weight: bold; }
#contant_body {
	float: right;
	width: 765px;
}
-->
</style>
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
#contant_body_header {
	background-image: url(../images/admin_supplier_inventory_header.png);
	height: 62px;
	width: 765px;
	margin-bottom: 10px;
}
#contant_body_body {
	width: 765px;
	margin-bottom: 10px;
}
.style4 {font-size: 12px}
#contant_body_1_1 {width: 737px;
	margin-right: 10px;
	margin-bottom: 10px;
	margin-left: 10px;
}
#contant_body_1_2 {	width: 737px;
	margin-right: 10px;
	margin-bottom: 10px;
	margin-left: 10px;
	height: 25px;
	background-image: url(../../admin/images/admin_order_productinfor_text.png);
}
#contant_body_1_3 {width: 737px;
	margin-right: 10px;
	margin-bottom: 10px;
	margin-left: 10px;
}
#contant_body_1_6 {width: 737px;
	margin-right: 10px;
	margin-bottom: 10px;
	margin-left: 10px;
}
#contant_body_1_text {	height: 25px;
	width: 737px;
	margin-right: 10px;
	margin-bottom: 10px;
	margin-left: 10px;
	background-image: url(../../admin/images/admin_order_text.png);
}
.style44 {color: #FF0000}
-->
</style>
<script language="javascript">
function checkoutF(){
	<?php 
		if($orderList->getStatus()==2){
				echo "alert(\"此訂單己點收過，無法再點收\");return;";
							
			}
			?>
	var check=document.getElementById("checkout").value;
	if(check=="true"){
		document.getElementById("form1").submit();
	}else{
		alert("庫存不足");
	}
}
<?php 
if(isset($_POST["checkout"])){
	if($_POST["checkout"]==true){
		if($orderList->getStatus()==1){
			if($prodAttrDBUtil->setOrderCheckOut($orderList->getOrderDetailArrayList())){
				echo "alert(\"訂單點收成功\")";			
				$orderListDBUtil->setOrderListCheck($orderList->getOl_id());
			}else{
				echo "alert(\"存貨數量不足，訂單點收失敗\")";
			}
		}else{
			echo "alert(\"此訂單已點收過\")";
		}
	}
}
?>
</script>
<!-- InstanceEndEditable -->
</head>

<body>
<table width="1024" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td>
		<div id="cantainer">
		<div id="header"></div>
		<div id="body">
		<div id="contant_list">
		<table border="0" align="center" cellpadding="0" cellspacing="0">
			<tr>
				<td align="center"><img src="../../images/index_12.png" width="180" height="54" /></td>
			</tr>
			<tr>
				<td>
				<table width="180" border="0" align="center" cellpadding="0" cellspacing="0" background="../../images/index_12_20.png">
					<tr>
						<td width="10"></td>
						<td><?php
						include_once '../common/menu.php';
						?></td>
						<td width="10"></td>
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td width="180" height="28" align="center">
				<table width="0" border="0" align="center" cellpadding="0"
					cellspacing="0">
					<tr>
						<td width="180" height="28" align="center"><img src="../../images/index_20.png" width="180" height="28" /></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</div>
		<!-- InstanceBeginEditable name="EditRegion1" -->
        <div id="contant_body">
          <div id="contant_body_header"></div>
          <div id="contant_body_body">
            <table cellpadding="0" cellspacing="0">
              <tr>
                <td colspan="3"><img src="../../member/img/member_body_up.jpg" width="765" height="9" /></td>
              </tr>
              <tr>
                <td width="4" background="../../member/img/member_body_left.jpg">&nbsp;</td>
                <td width="757"><div id="contant_body_1_text"></div>
                    <div id="contant_body_1_1">
                      <table width="737" cellspacing="0" cellpadding="5">
                        <tr>
                          <td width="100" class="style4">訂單日期</td>
                          <td class="style4"><?php echo $orderList->getOrderDate();?></td>
                        </tr>
                        <tr>
                          <td bgcolor="#D8F6F3" class="style4">訂單號碼</td>
                          <td bgcolor="#D8F6F3" class="style4"><?php echo $orderList->getOrder_no();?></td>
                        </tr>
                        <tr>
                          <td class="style4">供應商</td>
                          <td class="style4"><?php echo $orderList->getSupplierBrand()->getLogo_name();?></td>
                        </tr>
                        <tr>
                          <td bgcolor="#D8F6F3" class="style4">供應商地址</td>
                          <td bgcolor="#D8F6F3" class="style4"><?php echo $orderList->getOrder_addr();?></td>
                        </tr>
                        <tr>
                          <td class="style4">連絡電話</td>
                          <td class="style4"><?php echo $orderList->getOrder_tel();?></td>
                        </tr>
                      </table>
                    </div>
                  <div id="contant_body_1_2"></div>
                  <div id="contant_body_1_3">
                      <table width="737" cellspacing="0" cellpadding="5">
                        <tr>
                          <td align="center" bgcolor="#CCCCCC" class="style4">商品號碼</td>
                          <td align="center" bgcolor="#CCCCCC" class="style4"><p>商品名稱</p></td>
                          <td align="center" bgcolor="#CCCCCC" class="style4">販售方式</td>
                          <td align="center" bgcolor="#CCCCCC" class="style4">商品尺吋</td>
                          <td align="center" bgcolor="#CCCCCC" class="style4">商品數量</td>
                          <td align="center" bgcolor="#CCCCCC" class="style4">金額</td>
                          <td align="center" bgcolor="#CCCCCC" class="style4">貨品狀況</td>
                        </tr>
                        
                        <tr>
                          <td colspan="7" class="style4">
                          <?php
                          	$canBeCheckout=true; 
                        	for($i=0;$i<$orderList->getOrderDetailArrayList()->size();$i++){
                        		$count=$orderList->getOrderDetailArrayList()->get($i)->getProdAttr()->getCount()-$orderList->getOrderDetailArrayList()->get($i)->getCount();
                           ?>
                          <table width="729" cellspacing="0" cellpadding="5">
                              <tr <?php 
                              		if($count<0){
                              			echo "class='style44'";
                                }
                              ?>>
                                <td width="90" align="center"><?php         
                                	echo $orderList->getOrderDetailArrayList()->get($i)->getProdAttr()->getProduct()->getProd_no();?></td>
                                <td width="96" align="center"><?php echo $orderList->getOrderDetailArrayList()->get($i)->getProdAttr()->getProduct()->getP_name();?></td>
                                <td width="97" align="center"><?php 
                                switch($orderList->getOrderDetailArrayList()->get($i)->getProdAttr()->getProduct()->getSell_mode()){
                                case 1:
                          			echo "正品";
                          			break;
                          		case 2:
                          			echo "特價";
                          			break;
                          		case 3:
                          			echo "預售";
                          			break;
                          		case 4:
                          			echo "下架";
                          			break;
                                }
                                ?></td>
                                <td width="96" align="center"><?php echo $orderList->getOrderDetailArrayList()->get($i)->getProdAttr()->getAttr();?></td>
                                <td width="96" align="center"><?php echo $orderList->getOrderDetailArrayList()->get($i)->getCount();?></td>
                                <td width="96" align="center">NT$<?php echo number_format($orderList->getOrderDetailArrayList()->get($i)->getProdAttr()->getProduct()->getPrice(), 0, '.', ',');?></td>
                                <td width="86" align="center"><?php
                                 
                                if($count>=0){
                                	//庫存>訂貨數量
                                	echo "庫存充足";
                                }else if($count<0){
                                	echo "庫存不足";
                                	$canBeCheckout=false;
                                }
                                ?></td>
                              </tr>
                            </table>
                            <?php }?>
                            </td>
                        </tr>
                      </table>
                  </div>
                  <div id="contant_body_1_6">
                      <table width="737" cellspacing="0" cellpadding="5">
                        <tr>
                          <td align="center">
                          <form id="form1" name="form1" method="post" action="./admin_inventory_in_ifor.php">
                          	<input hidden name="ol_id" value="<?php echo $ol_id;?>" />
                          	<input hidden name="checkout" id="checkout" value="<?php 
                          	if($canBeCheckout){
                          		echo "true";
                          	}else{
                          		echo "false";
                          	
                          	}?>" />
                              <label>
                              <input type="button" name="button2" id="button2" onclick="checkoutF()"
                                   <?php
                                    if($orderList->getStatus()!=1 ){
                              			echo 'disabled="disabled"';
                              		}
                              		switch($orderList->getStatus()){
                              			case 0:
                              				echo "value=\"出貨中\"";
                              			case 2:
                              				echo "value=\"已點收\"";
                              			default:
                              			echo "value=\"點收\"";
                              		 }
                              
                              ?>/>
                            
                              <input type="button" name="button" id="button" value="回上一頁" onclick="javascript:history.back();"/>
                              </label>
                          </form></td>
                        </tr>
                      </table>
                  </div></td>
                <td width="4" background="../../member/img/member_body_right.jpg">&nbsp;</td>
              </tr>
              <tr>
                <td height="9" colspan="3"><img src="../../member/img/member_body_down.jpg" width="765" height="9" /></td>
              </tr>
            </table>
          </div>
        </div>
        <!-- InstanceEndEditable --></div>
      <div id="footer">
        <table width="955" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="230" height="118" align="center"><a href="index.html"><img width="200" height="66" alt="logo位置" style="background-color: #FF0000" /></a></td>
            <td width="10" align="center"><img src="../../images/end_Separateline1.png" width="1" height="80" /></td>
            <td width="715" valign="middle"><table width="715" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="40" valign="top" class="style2"><table border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <td width="50" align="center" class="style2"></td>
                        <td>本平台中台灣各店家所銷售的商品或服務，都是由各該店家所銷售或提供。 | 電話 : 02-2275-3588 | 傳真 : 02-2275-3788<br/>
                          微衡科技　版權所有 ⓒ 2011 Microbalance. All Rights Reserved.</td>
                      </tr>
                  </table></td>
                </tr>
            </table></td>
          </tr>
        </table>
      </div>
      </div></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>
